package function

import (
	"github.com/360EntSecGroup-Skylar/excelize"
	"github.com/gin-gonic/gin"
)

func Handle(r *gin.Engine) {
	//设置路由和方法
	r.GET("/ping", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "pong",
		})
	})
	r.GET("/excel", func(c *gin.Context) {
		f := excelize.NewFile()
		// 创建一个工作表
		index := f.NewSheet("Sheet2")
		// 设置单元格的值
		f.SetCellValue("Sheet2", "A2", "Hello world.")
		f.SetCellValue("Sheet1", "B2", 100)
		// 设置工作簿的默认工作表
		f.SetActiveSheet(index)

		c.Header("Content-Type", "application/octet-stream")
		c.Header("Content-Disposition", "attachment; filename="+"Workbook.xlsx")
		c.Header("Content-Transfer-Encoding", "binary")
		_ = f.Write(c.Writer)
	})

}
